package com.drojian.demo3.multimedia;

import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.drojian.demo.R;

public class VideoActivity extends AppCompatActivity implements View.OnClickListener{
    private VideoView video;
    private Button begin,stop,end;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.pary3_activity_video);
        initViews();
    }

    private void initViews() {
        video = findViewById(R.id.video);
        begin = findViewById(R.id.begin);
        stop = findViewById(R.id.stop);
        end = findViewById(R.id.end);
        begin.setOnClickListener(this);
        stop.setOnClickListener(this);
        end.setOnClickListener(this);
        //读取放在raw目录下的文件
        video.setVideoURI(Uri.parse("android.resource://com.drojian.demo/" + R.raw.video));
    }
        //根据文件路径播放
//        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
//            video.setVideoPath(Environment.getExternalStorageDirectory() + "/lesson.mp4");
//        }
//            video.setMediaController(new MediaController(this));
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.begin:
                video.start();
                break;
            case R.id.stop:
                video.pause();
                break;
            case R.id.end:
                video.stopPlayback();
                break;
        }
    }


}